package com.bean;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class DB {
    private Properties p;
    private String driver;
    private String url;
    private String username;
    private String password;
    private Connection conn;

    public Connection getConn() {
        return conn;
    }
    public DB(){
        try{
            p=new Properties();
            InputStream is=this.getClass().getResourceAsStream("/config.properties");
            System.out.println("p的值"+is);
            p.load(is);
            driver=p.getProperty("driver");
            url=p.getProperty("url");
            username=p.getProperty("username");
            password=p.getProperty("password");
            System.out.println("password"+password);
            Class.forName(driver);
            System.out.println("driver"+driver);
            conn= DriverManager.getConnection(url,username,password);
            System.out.println("conn"+conn);

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
